package com.eastchina.fids2focs.common.interceptor;

import java.text.MessageFormat;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MemoryWatchInterceptor implements MethodInterceptor {

    /**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 738414089087306512L;

	/**
	 * 日志出力对象
	 */
	private static final Log log = LogFactory.getLog(LoggingInterceptor.class);
    
	/**
	 * 日志出力形式
	 */
    protected static final MessageFormat format = new MessageFormat("Total Memory:{0} Free Memory:{1}");
    
    /**
     * 操作日志出力
     */
	public Object invoke(MethodInvocation invoker) throws Throwable {
		// 操作日志出力
		log.info(format.format(new Object[]{
				Runtime.getRuntime().totalMemory(),
				Runtime.getRuntime().freeMemory()
		}));
		return invoker.proceed();
	}
}
